package com.scm.controllor;

import java.io.IOException;
import java.sql.Connection;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.scm.dao.DBC;
import com.scm.dao.OPscmUser;
import com.scm.dao.OPuserModel;
import com.scm.model.ScmUser;
import com.scm.model.UserModel;

public class Login extends HttpServlet
{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		String n=req.getParameter("username");
		String p=req.getParameter("userpass");
		OPscmUser scmUser=new OPscmUser();
		ArrayList<ScmUser> list_user=scmUser.getScmUser(n);
		
		//用户输入密码与数据库密码，匹配
		if(list_user.get(0).getPassword().equals(p)){
			//得到用户的，模块
			OPuserModel usermModel=new OPuserModel();
			ArrayList<UserModel> list_model=usermModel.getModelCode(n);
			
			req.getSession().setAttribute("roller", list_model.get(0).getModelcode());
			req.getRequestDispatcher("main.html").forward(req, resp);
		}
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		doGet(req, resp);
	}

}
